package com.bosssoft.common.web;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: 你的名字
 * @Version: 1.0
 * @Date: 2024/07/31/21:27
 * @Description:
 */
import com.bosssoft.common.context.UserContextHandlerInterceptorV2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class WebConfig implements WebMvcConfigurer {
//    @Resource
//    private LoginInterceptor loginInterceptor;

    @Autowired
    private UserContextHandlerInterceptorV2 loginInterceptor;

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("http://localhost:8080")
                .allowedMethods("GET", "POST", "PUT", "DELETE")
                .allowedHeaders("*")
                .allowCredentials(true);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor).addPathPatterns("/**");
    }


}